package com.example.sanchuang_demo.web;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sanchuang_demo.domain.Region;
import com.example.sanchuang_demo.domain.School;
import com.example.sanchuang_demo.mapper.RegionMapper;
import com.example.sanchuang_demo.web.dto.RequestParam;
import com.example.sanchuang_demo.web.dto.ResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ResultHandler;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sc_demo/region")
@CrossOrigin
@Slf4j
public class RegionController {
    @Resource
    private RegionMapper regionMapper;
    @CrossOrigin
    @PostMapping("/list")
    public ResponseDto<?> list(@RequestBody RequestParam param){
        if(param.pageSize==null||param.pageNum==null){
            return new ResponseDto<>(false,"缺少pageSize或者pageNum字段",null);
        }
        Page<Region> page=new Page<>(param.pageNum,param.pageSize);

        QueryWrapper<Region> queryWrapper=new QueryWrapper<>();
        if(param.getPageNum()!=null)
            queryWrapper.like("region_name",param.keyword);
        return new ResponseDto<>(true,null, regionMapper.selectPage(page,queryWrapper));

    }


}
